import {Component, Input, Output, EventEmitter,} from '@angular/core';
import {NavController, NavParams} from 'ionic-angular';
import {HttpServies} from '../../providers/http-servies';
import  {ContactPage} from '../contact/contact';
import {SecondPage} from "../second/second";

import {ServicePage} from "../service/service";
import {WorkPage} from "../work/work";

@Component({
    selector: 'page-shoye',
    templateUrl: 'shoye.html',
    providers:[HttpServies]
})

export class ShoyePage {
    @Input() pageNum:number=1;//当前第几页,默认1
    @Output() pageNumChange = new EventEmitter<any>();
    ceil(num){
        return Math.ceil(num);
    }


    pageNumber: any = 0;
    dataJson: any = [];
    adJson: any = [];
    catJson:any=[];
    psJson:any=[];
    tpJson:any=[];
    num=1;
    userInfo={
        'keyword':'',
        'jobtitle':'',
        // 'companyname':'',

    }
    // jobtitle="";
    // companyname="";
    ionViewDidLoad() {
        this.getshoye();
        this.gettjzw();
        this.getgongao();
        this.tpgongao();
    }
    constructor(public navCtrl: NavController, public navParams: NavParams, private http: HttpServies) {
        // this.jobtitle=this.userInfo.jobtitle;
        // this.companyname=this.userInfo.companyname;

    }
    /*
     * 推荐职位跳转
     *
     * */
    strvaPage(jobinten){
        this.navCtrl.push(ContactPage,{jobinten});
    }
    /*
     * 点击全职跳转方法
     * */
    toContactPage() {
        this.navCtrl.push(ContactPage, {fulltime: 1});
    }
    /*
     * 点击兼职跳转方法
     * */
    ContactPage() {
        this.navCtrl.push(ContactPage, {fulltime: 0});
    }
    /*
     * 点击名企招聘跳转方法
     * */
    MqzpPage(){
        this.navCtrl.push(ContactPage,{mingqi:1});
    }
    //便民服务跳转
    toServicePage(){
        this.navCtrl.push(ServicePage);
    }
    //二手市场跳转
    codPage(){
        this.navCtrl.push(SecondPage);
    }
    //工作职位详情跳转
    woPage(jobinten,companyname){
        this.navCtrl.push(WorkPage,{jobinten,companyname});
    }

    /*
     * 搜索框方法
     * */
    checkInfo(){
        var param = "keyword="+this.userInfo.keyword;
        this.navCtrl.push(ContactPage,{param});
    }

    cheInfo(){
        this.navCtrl.push(ContactPage);
    }
    /*
     * 热门职位方法
     * */
    getshoye(){
        this.http.httpPost('/Home/index/hot')
            .then(res => {//成功
                if (res && res.code != 0) {
                    // this.http.showErro(res.msg);
                    console.log(res.msg);
                    this.adJson = res.data;
                }else {
                    this.adJson = res.data;
                }
            })
    }
    /*
     * 推荐职位方法
     *
     * */
    gettjzw(){
        var param = "num="+this.pageNum;
        this.http.httpPost('/Home/index/recommend',param)
            .then(res => {//成功
                if (res && res.code == 1) {
                    // this.http.showErro(res.msg);
                    console.log(res.msg);
                    this.catJson = res.data;
                }else {
                    this.catJson = res.data;
                }
            })
    }
    btnClick(pageNum){
        this.pageNum = pageNum;
        var param = "num="+this.pageNum;
        this.http.httpPost('/Home/index/recommend',param)
            .then(res => {//成功
                if (res && res.code == 1) {
                    console.log(res.msg);
                    this.catJson = res.data;
                }
            })
    }



    /*
     * 公告图片方法
     *
     * */
    getgongao(){
        this.http.httpPost('/Home/index/picture')
            .then(res => {//成功
                if (res && res.code == 1) {
                    console.log(res.msg);
                    this.psJson = res.data;
                }
            })
    }
    tpgongao(){
        this.http.httpPost('/Home/index/pictures')
            .then(res => {//成功
                if (res && res.code == 1) {
                    console.log(res.msg);
                    this.tpJson = res.data;
                }
            })
    }


}
